package com.example.pinkcat.activity.changuserinfo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.example.pinkcat.R;
import com.example.pinkcat.activity.api.getData.GetData;
import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class area extends AppCompatActivity {
    Context context=this;
    Spinner spinner;
    List<String> list = new ArrayList<String>();
    String area="河北省";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Objects.requireNonNull(getSupportActionBar()).hide();//去掉标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        setContentView(R.layout.activity_area);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }//深色信息栏
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);//允许此线程内发起网络请求

        spinner=(Spinner) findViewById(R.id.areaSpanner);
        setSpanner();
        listen();
    }
    void listen(){
        //返回键监听
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //确认修改键监听
        findViewById(R.id.change_enter).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (area==null){
                    Toast.makeText(context,"请输入信息",Toast.LENGTH_SHORT).show();
                }else {
                    if (GetData.updateMsg(area,"area",context))
                        onBackPressed();
                }
            }
        });
        //下拉框选择监听
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                area=list.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    void setSpanner(){
        list.add("河北省");
        list.add("山西省");
        list.add("辽宁省");
        list.add("吉林省");
        list.add("黑龙江省");
        list.add("江苏省");
        list.add("浙江省");
        list.add("安徽省");
        list.add("福建省");
        list.add("江西省");
        list.add("山东省");
        list.add("河南省");
        list.add("湖北省");
        list.add("湖南省");
        list.add("广东省");
        list.add("海南省");
        list.add("四川省");
        list.add("贵州省");
        list.add("云南省");
        list.add("陕西省");
        list.add("甘肃省");
        list.add("青海省");
        list.add("台湾省");
        list.add("北京市");
        list.add("天津市");
        list.add("上海市");
        list.add("重庆市");
        list.add("内蒙古自治区");
        list.add("广西壮族自治区");
        list.add("西藏自治区");
        list.add("宁夏回族自治区");
        list.add("新疆维吾尔自治区");
        list.add("香港特别行政区");
        list.add("澳门特别行政区");
        ArrayAdapter<String> spinner_adapter=new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,list);
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinner_adapter);
    }
}